package demo;

import Common.InfoCommon;
import org.neo4j.driver.*;
import org.neo4j.driver.types.Node;

import java.util.Arrays;

public class Neo4jDemo2 {
    public static void main(String[] args) {
        String url = InfoCommon.url;
        String username = InfoCommon.username;
        String password = InfoCommon.password;

        Driver driver = GraphDatabase.driver(url, AuthTokens.basic(username, password));
        Session session = driver.session();

        String cypherQuery = "MATCH (n:NorthDistrictPolygon) RETURN n";

        try {
            Result result = session.run(cypherQuery);

            // 执行Cypher查询

            // 输出结果
            while (result.hasNext()) {
                Record record = result.next();
                Node node = record.get("n").asNode();

                String type = String.valueOf(node.get("type"));
                String feature = String.valueOf(node.get("feature"));
                String bbox =  String.valueOf(node.get("bbox"));

                // 输出节点的属性
                System.out.println("---------------------------------------");
                System.out.println("Node ID: " + node.id());

                if( type != null &&  feature != null  && !type.equals("NULL") && !feature.equals("NULL") ){
                    System.out.println(type+" : "+feature);
                }else {
                    System.out.println("没有type属性");
                }
                System.out.println("位置:"+bbox);

                System.out.println("Node Properties: " + node.asMap());
            }
        }catch(Exception e){
            e.printStackTrace();
        }
    }




}

